//
//  XTCShowIndex.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/4/16.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XTCShowIndex.h"
#import "XXTool.h"

@interface XTCShowIndex ()

@property (nonatomic,strong) UILabel *showIndex;

@end

@implementation XTCShowIndex
-(UILabel*)showIndex
{
    if (_showIndex==nil)
    {
        _showIndex = [[UILabel alloc] init];
        _showIndex.font = [XXTool systemFontOfSize:16.5];
        _showIndex.textColor = [UIColor whiteColor];
        _showIndex.numberOfLines = 0;
        [self addSubview:_showIndex];
    }
    return _showIndex;
}

-(void)initUI
{
    self.backgroundColor = [UIColor clearColor];
    [self showIndex];
}

-(void)refreshLayout:(CGRect)frame
{
    _showIndex.frame = CGRectMake(15
                                      , 18
                                      , frame.size.width-30
                                      , [XXTool getTextHeightByText:_showIndex.text
                                                               Font:_showIndex.font
                                                              Width:_showIndex.frame.size.width]);
}

-(void)setCellWithData:(id)model
{
    
    if ([model isKindOfClass:[RXMLExhibitorIndexModel class]]||[model isKindOfClass:[RXMLCountryIndex class]])
    {
        _showIndex.textColor = [UIColor whiteColor];
        RXMLExhibitorIndexModel *temp = model;
        if ([XXTool didCurrentLanguageChinese])
        {
            _showIndex.text = temp.index_name_cn;
        }
        else
        {
            _showIndex.text = temp.index_name_en;
        }
        
        if (temp.index_have_fa==0)
        {
            self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else
        {
            self.accessoryType = UITableViewCellAccessoryNone;
        }
    }
    else if ([model isKindOfClass:[RXMLExhibitorInformationModel class]])
    {
        _showIndex.textColor = [UIColor blackColor];
        RXMLExhibitorInformationModel *temp = model;
        NSString *showText = @"";
        if (![temp.CompanyName_eng isEqualToString:@""]&&![temp.CompanyName_chn isEqualToString:@""])
        {
            showText = [NSString stringWithFormat:@"%@\n%@",temp.CompanyName_eng,temp.CompanyName_chn];
        }
        else if ([temp.CompanyName_chn isEqualToString:@""])
        {
            showText = temp.CompanyName_eng;
        }
        else if ([temp.CompanyName_eng isEqualToString:@""])
        {
            showText = temp.CompanyName_chn;
        }
        _showIndex.text = showText;
    }
    
    [self refreshLayout:self.frame];
}

+(CGFloat)getCellHeightWithData:(id)model
{
    NSString *showText = @"";
    
    if ([model isKindOfClass:[RXMLExhibitorIndexModel class]]||[model isKindOfClass:[RXMLCountryIndex class]])
    {
        RXMLExhibitorIndexModel *temp = model;
        if ([XXTool didCurrentLanguageChinese])
        {
            showText = temp.index_name_cn;
        }
        else
        {
            showText = temp.index_name_en;
        }
    }
    else if ([model isKindOfClass:[RXMLExhibitorInformationModel class]])
    {
        RXMLExhibitorInformationModel *temp = model;
        if (![temp.CompanyName_eng isEqualToString:@""]&&![temp.CompanyName_chn isEqualToString:@""])
        {
            showText = [NSString stringWithFormat:@"%@\n%@",temp.CompanyName_eng,temp.CompanyName_chn];
        }
        else if ([temp.CompanyName_chn isEqualToString:@""])
        {
            showText = temp.CompanyName_eng;
        }
        else if ([temp.CompanyName_eng isEqualToString:@""])
        {
            showText = temp.CompanyName_chn;
        }
    }
    return 36+[XXTool getTextHeightByText:showText
                                     Font:[XXTool systemFontOfSize:16.5]
                                    Width:[UIScreen mainScreen].bounds.size.width-30];
}

@end
